classdef Car
    

    properties (Access = private)
        init_speed;
        acc;
        speed;
        %Car 这是一个匀加速直线运动的小车类
    %  这是classdef的定义
    end
    %Car 创建Car类实例
            %   这是一个匀加速直线运动的小车类(构造函数)

    methods
        function obj = Car(init_speed, acc)
            
            obj.init_speed = init_speed;
            obj.acc = acc;
        end

        function cur_speed = getSpeed(obj, t)
            %getSpeed 计算当前速度
            %   v = v0 + a*t
            cur_speed = obj.init_speed + t * obj.acc;
        end

        function cur_dist = getDist(obj, t)
            %getSpeed 计算当前位移
            %   x = v0*t + 0.5*a*t*t
            cur_dist = 0.5*obj.acc*t.^2 + obj.init_speed * t;
        end
    end
end